<template>
	<view class="container" style="padding-bottom: 120rpx;">
		<u--form ref="queryForm" :model="query">
			<u-form-item label="储位码" prop="storageCode" labelWidth="100rpx">
				<u--input
					placeholder="请输入/扫描"
					v-model.trim="query.storageCode"
					suffixIcon="scan"
					suffixIconStyle="font-size: 68rpx"
					style="flex: 1;"
				>
				</u--input>
			</u-form-item>
		</u--form>
		<!-- 提示组件 -->
		<u-toast ref="uToast"></u-toast>
		<view class="commonButton">
		  <u-button type="primary" @click="callEmpty">呼叫空容器</u-button>
		</view>
	</view>
</template>

<script>
	import { callEmptyAPI } from '@/api/work/callCar.js'
	export default {
		data() {
			return {
				query: {
					storageCode: ''
				}
			};
		},
		onLoad(options) {
			uni.$on('scancodedate',(data) => this.getCode(data.code))
		},
		onUnload() {  
		  // 移除监听事件      
		  uni.$off('scancodedate')
		},
		methods: {
			getCode(code) {
				// const pattern = /^[A-Za-z]\d{9}$/
				if (code.includes('-')) {
					this.query.storageCode = code
				}
			},
			async callEmpty() {
				if (!this.query.storageCode) {
					return this.$refs.uToast.show({
						type: 'warning',
						message: '请扫描储位码'
					})
				}
				const res = await callEmptyAPI(this.query.storageCode)
				if (res.meta.code === 200) {
					this.$refs.uToast.show({
						type: 'success',
						message: res.meta.msg
					})
					this.query.storageCode = ''
				} else {
					this.$refs.uToast.show({
						type: 'warning',
						message: res.meta.msg
					})
				}
			}
		}
	}
</script>

<style lang="scss">
.commonButton {
	width: 100%;
	display: flex;
	gap: 20rpx;
	position: fixed;
	left: 0;
	bottom: 0;
	box-sizing: border-box;
	padding: 15rpx;
	justify-content: space-between;
}
</style>
